package com.caszx.chargingpile.holder.reservate;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import com.app.base.adapter.holder.BaseHolder;
import com.caszx.chargingpile.R;
import com.caszx.chargingpile.entity.EntitySubscribe;
import com.caszx.chargingpile.user.LocationManager;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import de.greenrobot.event.EventBus;

/**
 * 预约中
 */
public class ReservateRecordHolder extends BaseHolder<EntitySubscribe> implements View.OnClickListener {


    private TextView txtTitle;
    private TextView txtDistance;
    private TextView txtNumber;
    private TextView txtPayStatus;
    private TextView txtInfo;

    private TextView btn_reservate;
    private TextView btn_delete;

    DecimalFormat decimalFormat = new DecimalFormat("###.##Km");
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
    public ReservateRecordHolder(View view) {
        super(view);
    }

    @Override
    protected void initView() {
        txtTitle = (TextView) mRootView.findViewById(R.id.txtTitle);
        txtDistance = (TextView) mRootView.findViewById(R.id.txtDistance);
        txtNumber = (TextView) mRootView.findViewById(R.id.txtNumber);
        txtPayStatus = (TextView) mRootView.findViewById(R.id.txtPayStatus);
        txtInfo = (TextView) mRootView.findViewById(R.id.txtInfo);
        btn_reservate = (TextView) mRootView.findViewById(R.id.btn_reservate);
        btn_delete = (TextView) mRootView.findViewById(R.id.btn_delete);
        btn_reservate.setOnClickListener(this);
        btn_delete.setOnClickListener(this);

    }

    @Override
    protected void refreshView() {

        txtTitle.setText(mItem.stationName);
        txtDistance.setText(decimalFormat.format(mItem.distence/1000));
        txtNumber.setText("桩编号: "+mItem.pileNo+"  枪编号:"+mItem.gunNo);
        txtInfo.setText("预约时间  "+dateFormat.format(new Date(mItem.startDate))+"  至  "+dateFormat.format(new Date(mItem.endDate)));
        if(0 == mItem.payStatus){
            //未支付
            txtPayStatus.setText("代支付");
            txtPayStatus.setTextColor(Color.parseColor("#FFFE7802"));
            btn_reservate.setText("去支付");
        }else  if(1 == mItem.payStatus){
            //已支付
            txtPayStatus.setText("已支付");
            txtPayStatus.setTextColor(mRootView.getResources().getColor(R.color.colorAccent));
            btn_reservate.setText("去这里");
        }
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){

            case R.id.btn_reservate:
                if(0 == mItem.payStatus){
                    //未支付,去支付

                }else  if(1 == mItem.payStatus){
                    //已支付,根据坐标，百度导航
                    double start_longitude = LocationManager.getInstance().getLongitude();
                    double start_latitude  =  LocationManager.getInstance().getLatitude();
                    String start_title = LocationManager.getInstance().getCityName();

                    double end_longitude = mItem.longitude;
                    double end_latitude  = mItem.latitude;
                    String end_title = mItem.stationName;
                    LocationManager.getInstance().routeplanToNavi((Activity) mRootView.getContext(),start_longitude,start_latitude,start_title
                            ,end_longitude,end_latitude,end_title );

                }

                break;
            case R.id.btn_delete:
                //发出取消预约
                EventBus.getDefault().post(mItem);
                break;

        }
    }
}
